home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: To find the class of an object ??
- Date: 29 Feb 1996 00:43:33 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4h2srl$8dj@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe3.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 27, 1996 17:22:46 in article <To find the class of an object ??>,
- 'didier@cln46ib (Didier BOLF)' wrote:
-
-
- >
- >I have a class A and a class B. The class B inherit the class A.
- >I have too: A tab[MAX];
- >In tab, I put objets of class A or B.
- >
- >How compare two objects of tab to know if they are of the same class ??
- >and which class they belong to ??
- >
- If your compiler supports RTTI -- and many older ones do not -- you can
- use the typeid operator. Read your online docs for more info.
-
- If not, then you can define virtual functions for each of your
- classes; for example:
-
- class Base
- {
- virtual const char * TypeOf() const { return "Base"; }
- ...};
-
- class Derived
- {
- virtual const char * TypeOf() const { return "Derived"; }
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-